<?php

namespace Admin\Controller;

use Org\Net\Http;
use Think\Image;
use Think\Page;
use Think\Controller;

class AccountController extends AuthController {
	public function index() {
		$account = D('Account');
		$list = $account->order('ctime desc')->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function integral() {
		$account = D('Account');
		$list = $account->field("nickname,headimgurl,integral")->limit(10)->order('integral desc')->select();
		$this->assign('list',$list);
		$data = array();
		foreach ($list as $item){
			$d = array();
			$d[] = $item['nickname'];
			$d[] = $item['integral'];
			$data[] = $d;
		}
		$this->assign('data',$data);
		$this->display();
	}
	public function credit() {
		$account = D('Account');
		$list = $account->field("nickname,headimgurl,gameCredits")->limit(10)->order('gameCredits desc')->select();
		$this->assign('list',$list);
		$data = array();
		foreach ($list as $item){
			$d = array();
			$d[] = $item['nickname'];
			$d[] = $item['gamecredits'];
			$data[] = $d;
		}
		$this->assign('data',$data);
		$this->display();
	}
	public function active(){
		$date = I('date');
		if(!$date){
			$date = date("Y-m");
		}
		$where['ctime'] = array('like',"{$date}%");
		$time = M('Time');
		$list = $time->where($where)->group("ctime")->field("ctime,COUNT(distinct aid) as num")->select();
		$this->assign('list',$list);
		foreach ($list as $item){
			$d = array();
			$d[] = $item['ctime'];
			$d[] = $item['num'];
			$data[] = $d;
		}
		$this->assign('data',$data);
		$this->display();
	}
	public function time(){
		$date = I('date');
		if(!$date){
			$date = date("Y-m");
		}
		$where['ctime'] = array('like',"{$date}%");
		$list = M()->query('select a.nickname,a.headimgurl,SUM(t.time) as time FROM qms_time t LEFT JOIN qms_account a ON a.id = t.aid GROUP BY t.aid;');
		$this->assign('list',$list);
		foreach ($list as $item){
			$d = array();
			$d[] = $item['nickname'];
			$d[] = $item['time'];
			$data[] = $d;
		}
		$this->assign('data',$data);
		$this->display();
	}
	public function area(){
		$account = M('Account');
		$list = $account->where($where)->group("province")->field("id,province as label,COUNT(*) as data")->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function user(){
		$date = I('date');
		if(!$date){
			$date = date("Y-m");
		}
		$where['ctime'] = array('like',"{$date}%");
		$time = M('Time');
		$list = $time->where($where)->group("ctime")->field("ctime,COUNT(*) as num")->select();
		var_dump($list);
		$list = $time->where($where)->group("ctime,aid")->field("aid,ctime,SUM(time) as time")->select();
		var_dump($list);
		$list = $time->where($where)->group("ctime")->field("ctime,COUNT(distinct aid) as num")->select();
		var_dump($list);
		$list = $time->where($where)->group("ctime")->field("ctime,SUM(time) as time")->select();
		var_dump($list);
		$list = $time->group("aid")->field("aid,MAX(credit),SUM(credit) as credit,SUM(time) as time")->select();
		var_dump($list);
	}
}